When a star is too small, don't draw it.
private void drawStar( Graphics gr, int x, int y, int size ) { int endX ; int endY ; if ( size <= 2 ) return; // Six lines radiating from (x,y) for ( int i = 0; i<6; i++ ) { endX = x + (int)(size*Math.cos( (2*Math.PI/6)*i )); endY = y - (int)(size*Math.sin( (2*Math.PI/6)*i )); gr.drawLine( x, y, endX, endY ); drawFlake( gr, endX, endY, size/3 ); } }
This is a somewhat hard thought, and I suggest that you get out pencil and paper and draw some stars attached to stars attached to stars. After a while it is clear that you want to stop drawing when the stars are too small to draw.
Decide on a limit for size
that is small enough,
and test for it.
When the limit is reached, just return to the caller:
if ( size <= 2 ) return;
I picked the value "2" for the base case. Smaller values result in cluttered snowflakes.
In this code, if the if
statement followed the
for
statement, would everything be OK?